home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmClient
- Caption = "TCP/IP Chat Client"
- ClientHeight = 5295
- ClientLeft = 1005
- ClientTop = 1905
- ClientWidth = 9480
- Height = 5700
- Left = 945
- LinkTopic = "Form1"
- ScaleHeight = 5295
- ScaleWidth = 9480
- Top = 1560
- Width = 9600
- Begin VB.Frame Frame1
- Height = 1365
- Left = 0
- TabIndex = 2
- Top = 3930
- Width = 9465
- Begin VB.TextBox txtMessage
- BeginProperty Font
- name = "Terminal"
- charset = 1
- weight = 700
- size = 9
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 915
- Left = 90
- MaxLength = 240
- MultiLine = -1 'True
- TabIndex = 5
- Top = 360
- Width = 8025
- End
- Begin VB.CommandButton cmdSend
- Caption = "Send"
- Default = -1 'True
- Height = 420
- Left = 8190
- TabIndex = 4
- Top = 360
- Width = 1185
- End
- Begin VB.CommandButton cmdExit
- Caption = "Exit"
- Height = 420
- Left = 8190
- TabIndex = 3
- Top = 855
- Width = 1185
- End
- Begin VB.Label Label2
- Caption = "Enter Message here:"
- Height = 285
- Left = 90
- TabIndex = 7
- Top = 135
- Width = 3885
- End
- End
- Begin VB.ListBox lstNames
- Height = 3570
- ItemData = "FRMCHAT.frx":0000
- Left = 7530
- List = "FRMCHAT.frx":0002
- TabIndex = 0
- Top = 360
- Width = 1920
- End
- Begin VB.Label Label1
- Caption = "Currently Chatting:"
- Height = 285
- Left = 7650
- TabIndex = 6
- Top = 90
- Width = 1905
- End
- Begin CITCPLib.CITCP tcpChat
- Height = 450
- Left = 6930
- Top = 3420
- Width = 480
- _version = 65536
- _extentx = 847
- _extenty = 794
- _stockprops = 0
- hostname = ""
- hostaddress = ""
- servicename = ""
- port = 2000
- End
- Begin PdqcommLib.PDQComm pdqTerm
- Height = 3780
- Left = 0
- TabIndex = 1
- Top = 90
- Width = 7410
- _version = 196609
- _extentx = 13070
- _extenty = 6668
- _stockprops = 4
- BeginProperty font {FB8F0823-0164-101B-84ED-08002B2EC713}
- name = "Terminal"
- charset = 1
- weight = 400
- size = 9
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- autosize = -1 'True
- backcolor = 8
- columns = 60
- emulation = 2
- fastscroll = 0 'False
- forecolor = 9
- Object.height = 252
- rows = 21
- scrollrows = 540
- Object.width = 480
- appearance = 1
- End
- Attribute VB_Name = "frmClient"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Dim Connect As Boolean
- Private Sub cmdExit_Click()
- ' Send an exit message to the screen and unload the file.
- tcpChat.Send "~|exit" & ScreenName
- Unload Me
- End Sub
- Private Sub cmdSend_Click()
- 'check if there is any text to send
- If txtMessage.Text = "" Then Exit Sub
- 'append screenname to message and send to TCP/IP server
- tcpChat.Send ScreenName & "> " & txtMessage.Text
- 'Clear textbox and setfocus back.
- txtMessage.Text = ""
- txtMessage.SetFocus
- End Sub
- Private Sub Form_Activate()
- txtMessage.SetFocus
- End Sub
- Private Sub Form_Load()
- Dim Result As Integer
- 'center form on screen
- Me.Top = Screen.Height / 2 - Me.Height / 2
- Me.Left = Screen.Width / 2 - Me.Width / 2
- 'display chat window
- Me.Show
- Screen.MousePointer = 11
- pdqTerm.Disp = "
- [1;32m" & "Attempting connection to host" & vbCrLf & "
- [1;34m"
- DoEvents
- 'set tcp/ip controls properties Port, Hostname or Address
- tcpChat.Port = PortNum
- If HostName <> "" Then
- tcpChat.HostName = HostName
- tcpChat.HostAddress = HostAddress
- End If
- 'attempt connection to CISERVER Host
- Result = tcpChat.ConnectToHost
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- 'Close the Socket
- tcpChat.CloseSocket
- DoEvents
- End Sub
- Private Sub lstNames_DblClick()
- txtMessage.SetFocus
- End Sub
- Private Sub tcpChat_Connection(ByVal address As String)
- Connect = True
- 'send ScreenName to tcpserver
- tcpChat.Send "~|name=" & ScreenName
- 'dispay success message to terminal
- pdqTerm.Disp = "
- [1;32m" & "Host Contacted" & vbCrLf & vbCrLf & "
- [1;34m"
- Screen.MousePointer = 0
- End Sub
- Private Sub tcpChat_PacketReceived(Packet As Variant, ByVal bytes_in As Integer)
- Dim i As Integer
- Dim sent As Boolean
- Dim done As Boolean
- Dim message As String
- 'test if we have received a screenname and add to listbox
- If Left(Packet, 7) = "<Names>" Then
- lstNames.Clear
- message = Right(Packet, Len(Packet) - 7)
- Do
- i = InStr(message, Chr(13))
- If i Then
- lstNames.AddItem Left(message, i - 1) 'Add name to listbox
- message = Right(message, Len(message) - i)
- End If
- Loop Until message = ""
- ' test if server denied connection
- If Packet = "Sorry, No more connections accepted at this time" Then
- 'Maximum number of connections reached
- MsgBox "Sorry, the server is not accepting anymore connections", 0, "Unable to connect"
- Unload Me
- End
- End If
- ' display packet to terminal window
- 'first extract name and display in color
- i = InStr(Packet, ">")
- sname = Left(Packet, i)
- i = Len(sname)
- pdqTerm.Disp = "
- [1;36m" & sname & "
- [1;34m"
- 'break up remainder of message adding word wrap
- 'for terminal window display
- message = Right(Packet, Len(Packet) - i)
- Do
- 'Checking the character length breaks of characters of 60
- If Len(message) <= 60 - i Then
- pdqTerm.Disp = message
- If Len(message) + i < 60 Then pdqTerm.Disp = vbCrLf
- sent = True
- Else
- pos = 61 - i
- Do
- If Mid(message, pos, 1) = " " Then
- pdqTerm.Disp = Left(message, pos - 1)
- If Len(Left(message, pos)) + i <= 60 Then pdqTerm.Disp = vbCrLf
- message = Right(message, Len(message) - pos)
- done = True
- Else
- pos = pos - 1
- End If
- Loop Until done Or pos = 1
- If pos = 1 Then
- pdqTerm.Disp = Left$(message, 60 - i)
- message = Right$(message, Len(message) - 60 + i)
- End If
- i = 0
- pos = 60
- done = False
- End If
- Loop Until sent
- 'Add carriage return/linefeed
- pdqTerm.Disp = vbCrLf
- End If
- End Sub
- Private Sub tcpChat_WSAError(ByVal error_number As Integer)
- ' If Error is detected this event will fire and alert user
- ' to what the issue may be.
- If Not Connect Then
- 'If connection fails alert user
- Screen.MousePointer = 0
- pdqTerm.Disp = "
- [1;32m" & "Unable to establish connection to host" & vbCrLf & "WinSock Error #" & error_number & " occured. Error during connection" & "
- [1;34m"
- MsgBox "Unable to connect to host", 0, "Connection Error"
- Unload Me
- frmSetup.Show
- Exit Sub
- ' Display Winsock Error
- pdqTerm.Disp = "
- [1;32m" & "WinSock Error #" & error_number & " occured" & "
- [1;34m" & vbCrLf & vbCrLf
- End If
- End Sub
-